//
//  CWtabbar.swift
//  weibo10
//
//  Created by Apple on 16/5/10.
//  Copyright © 2016年 Apple. All rights reserved.
//

import UIKit

class CWtabbar: UITabBar
{
    
    var modelVC:(() -> ())?

  
    override func layoutSubviews()
    {
        super.layoutSubviews()
        
        let width = self.frame.size.width / 5
        var index:CGFloat = 0
        
        
        for view in self.subviews
        {
            if view.isKindOfClass(NSClassFromString("UITabBarButton")!)
            {
        
            view.frame = CGRect(x:index * width , y: 0, width:width, height:self.frame.size.height)
            index++
                if index == 2
                {
                    
                    index++
                }
            }
            composebutton.frame = CGRect(x: 2 * width, y: 0, width: width, height:self.frame.size.height)
        
        }
    }
    
    
    func composebuttonClick(btn:UIButton){
    
        modelVC?()
    
    
    }
    
    
//MARK: - 懒加载
    lazy var composebutton:UIButton = {
    
        
        let button = UIButton(type: UIButtonType.Custom)
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: UIControlState.Highlighted)
        
        button.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: UIControlState.Normal)
        button.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: UIControlState.Highlighted)
    
        self.addSubview(button)
        
        button.addTarget(self, action: "composebuttonClick:", forControlEvents:UIControlEvents.TouchUpInside)
        return button
    
    }()

}
